﻿Imports System.Collections.Generic
Public Class LoaiMonDao
    'phuong thuc lay danh sach dua vao ma mon

    Public Shared Function LayDanhSach() As List(Of CLoaiMon)
        Dim kq As List(Of CLoaiMon) = New List(Of CLoaiMon)
        Dim str As String = String.Format("SELECT * from LoaiMon")
        Dim dt As DataTable = CKetNoi.ExecQuery(str)
        For Each i As DataRow In dt.Rows
            Dim mloai As New CLoaiMon
            mloai.MaLoai = i("MaLoai")
            mloai.TenLoai = i("TenLoai")
            kq.Add(mloai)
        Next
        Return kq
    End Function
    Public Shared Function Insert(ByVal b As CLoaiMon) As Integer
        Dim sql As String = String.Format("INSERT INTO LoaiMon(MaLoai,TenLoai) VALUES('{0}','{1}')", b.MaLoai, b.TenLoai)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function Delete(ByVal maloai As String) As Integer
        Dim sql As String = String.Format("Delete from LoaiMon where MaLoai='{0}'", maloai)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function Update(ByVal b As CLoaiMon) As Integer
        Dim sql As String = String.Format("Update LoaiMon set TenLoai='{0}'", b.TenLoai)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
End Class
